package com.easytopit.demo.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.easytopit.demo.dao.CinemaMapper;
import com.easytopit.demo.domain.Cinema;
import com.easytopit.demo.exception.BizException;
import com.easytopit.demo.service.CinemaService;

/**
 * @author YWQ
 *
 */
@Service
public class CinemaServiceImpl implements CinemaService{

	@Autowired
	private CinemaMapper cinemaMapper;
	
	@Override
	public Cinema add(String name, String address, String phone, String features, Integer quantity, String hallName,
			Double score) throws BizException {
		if (name == null) throw new BizException("影院名称不能为空"); 
		if (address == null) throw new BizException("影院地址不能为空"); 
		if (phone == null) throw new BizException("影院电话不能为空"); 
		if (features == null) throw new BizException("影院特色不能为空"); 
		if (quantity == null) throw new BizException("影院数量不能为空"); 
		if (hallName == null) throw new BizException("影厅名称不能为空"); 
		if (score == null) throw new BizException("影院评分不能为空"); 
			
		Cinema cinema = new Cinema();
		cinema.setName(name);
		cinema.setAddress(address);
		cinema.setPhone(phone);
		cinema.setFeatures(features);
		cinema.setQuantity(quantity);
		cinema.setHallName(hallName);
		cinema.setScore(score);
		Integer insert = cinemaMapper.insert(cinema);
		if (insert != null) return cinema;
		return null;
	}

	@Override
	public Integer update(String name, String address, String phone, String features, Integer quantity, String hallName,
			Double score) throws BizException {
		return cinemaMapper.update(name, address, phone, features, quantity, hallName, score);
	}
}